package day2003;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class khd {//客户端
    public static void main(String[] args) throws IOException, InterruptedException {
        //链接服务器//本机又当服务器，又当客户端（访问自己127.0.0.1）
        Socket a = new Socket("172.18.6.82",8000);
        System.out.println("与服务器建立连接");

        //给服务器发送数据
        OutputStream b =a.getOutputStream();
        b.write("hello".getBytes());
        b.flush();


        //客户端接收数据
        InputStream d = a.getInputStream();

        char[] xxx = new char[5];
        for (int i=0;i<5;i++){
            xxx[i]= (char) d.read();
        }
        System.out.println(new String(xxx));
    }
}
